package zhh.tangbao.auxiliary.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhh.tangbao.auxiliary.dto.opinion.OpinionQueryDto;
import zhh.tangbao.auxiliary.dto.opinion.UpdateResponseDto;
import zhh.tangbao.auxiliary.service.SystemOpinionService;
import zhh.tangbao.auxiliary.vo.opinion.OpinionInfoVo;
import zhh.tangbao.auxiliary.vo.opinion.OpinionPageVo;
import zhh.tangbao.auxiliary.vo.opinion.OpinionTypeSelectOptionVo;
import zhh.tangbao.system.annotation.Authority;
import zhh.tangbao.system.annotation.Log;
import zhh.tangbao.system.entity.PagerEntity;
import zhh.tangbao.system.result.Result;

import java.util.List;

/**
 * <p>
 * 描述
 * </p>
 *
 * @author 粥灰灰
 * <p>2023/4/26</p>
 */

@RestController
@RequestMapping("/api/opinion")
public class SystemOpinionController {

    @Autowired
    private SystemOpinionService service;

    /**
     * 老式分页
     */
    @GetMapping("/page")
    public Result page(PagerEntity<OpinionPageVo> pager, OpinionQueryDto dto) {
        return Result.success().put(service.page(pager, dto));
    }

    @GetMapping("/opinionType")
    public Result opinionType() {
        List<OpinionTypeSelectOptionVo> vos = service.opinionType();
        return Result.success().put(vos);
    }

    @GetMapping("/get/{id}")
    public Result get(@PathVariable("id") String id) {
        OpinionInfoVo vo = service.get(id);
        return Result.success().put(vo);
    }

    @PutMapping("/updateResponse")
    @Authority
    @Log(function = "回复反馈意见", moduleName = "反馈意见")
    public Result updateResponse(@RequestBody UpdateResponseDto dto) {
        int i = service.updateResponse(dto);
        return Result.successOrFail(i);
    }


}
